#include <cstdio>
#include <cctype>
#include <algorithm>

#define vfirst ('A')
#define vlast ('Z' + 1)

#define get_int(n) scanf("%d", &n)


struct Letter
{
	int letter;
	int count;

	bool operator < (const Letter &l) const {
		if (this->count > l.count)
			return true;
		return this->count == l.count && this->letter < l.letter;
	}
};


int main ()
{
	Letter l[vlast];
	int c, lines, total_lines;

	for (c = vfirst; c < vlast; ++c) {
		l[c].letter = c;
		l[c].count = 0;
	}

	get_int(total_lines);
	lines = 0;
	while (lines <= total_lines && (c = getchar()) > 0)
	{
		if (isalpha(c)) {
			c = toupper(c);
			++l[c].count;
		}
		else if (c == '\n')
			++lines;
	}

	std::sort (l + vfirst, l + vlast);

	for (c = vfirst; c < vlast; ++c)
	{
		Letter &letter = l[c];
		if (letter.count == 0)
			break;
		printf("%c %d\n", letter.letter, letter.count);
	}

	return 0;
}